<?php
if (!defined('WEB_ROOT')) {
	exit;
}
if (isset($_GET['nn_id']) && $_GET['nn_id'] > 0) {
	$nn_id = (int)$_GET['nn_id'];
	$queryString = "&nn_id=$nn_id";
} else {
	$nn_id = 0;
	$queryString = '';
}
	
// for paging
// how many rows to show per page
$rowsPerPage = 5;

$sql = "SELECT madt, tendt, ngaybatdau, ngayketthuc, cap, trangthai, dv_id
        FROM detai dt left join tacgia_detai tgd ON dt.id = tgd.dt_id
		ORDER BY dt.id desc";
//echo $sql;
$result     = dbQuery(getPagingQuery($sql, $rowsPerPage));
$pagingLink = getPagingLink($sql, $rowsPerPage);
		
$groupList = buildGroupOptions($mannc);

?> 
<br />
<form action="processTopic.php?action=addTopic" method="post"  name="frmListTopic" id="frmListTopic">
 <table width="100%" border="0" cellspacing="0" cellpadding="2" class="text">
  <tr>
   <td align="right">View Topics in : 
    <select name="cboGroup" class="box" id="cboGroup" onChange="viewTopic();">
     <option selected>All Group</option>
	<?php echo $groupList; ?>
   </select>
 </td>
 </tr>
</table>
 <table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="text">
	  <tr align="center" id="listTableHeader"> 
		   <td width="80">Mã đề tài</td>
		   <td>Tên đề tài</td>
			<!--   <td width="75">Hình ảnh</td>-->
		   <td width="80">Ngày bắt đầu</td>
		   <td width="80">Ngày kết thúc</td>
		   <td width="70">Cấp</td>
		   <td width="70">Trạng thái</td>
		   <td width="130">Đơn vị</td>
		   <td width="40">Sửa</td>
		   <td width="40">Xóa</td>
	  </tr>
  <?php
if (dbNumRows($result) > 0) {
	$i = 0;
	
	while($row = dbFetchAssoc($result)) {
		extract($row);
		if ($i%2) {
			$class = 'row1';
		} else {
			$class = 'row2';
		}	
		$i += 1;
?>
  <tr class="<?php echo $class; ?>"> 
	   <!--<td width="90" align="center"><a href="index.php?view=detail&id=<?php echo $id; ?>"><?php echo $matg; ?></a></td>-->
	   <td width="80"><?php echo $madt; ?></td>
 	   <td align="center"><?php echo $tendt; ?></td>
	   <td width="80" align="center"><?php echo $ngaybatdau; ?></td>
	   <td width="80" align="center"><?php echo $ngayketthuc; ?></td>
	   <td width="70" align="center"><?php echo $cap; ?></td>
	   <td width="70" align="center"><?php echo $chuoitrangthai = ($trangthai < 0) ? 'Đã hủy':(($trangthai==0)?'Đang tiến hành':'Đã hoàn thành');?></td>
	   <td width="130" align="center"><?php echo $donvi; ?></td>
	   <td width="40" align="center"><a href="javascript:modifyTopic(<?php echo $id; ?>, <?php echo (int)$nn_id; ?>);">Sửa</a></td>
	   <td width="40" align="center"><a href="javascript:deleteTopic(<?php echo $id; ?>, <?php echo $nn_id; ?>);">Xóa</a></td>
  </tr>
  <?php
	} // end while
?>
  <tr> 
   <td colspan="5" align="center">
   <?php 
echo $pagingLink;
   ?></td>
  </tr>
<?php	
} else {
?>
  <tr> 
   <td colspan="5" align="center">Không có đề tài nghiên cứu khoa học nào</td>
  </tr>
  <?php
}
?>
  <tr> 
   <td colspan="5">&nbsp;</td>
  </tr>
  <tr> 
   <td colspan="5" align="right"><input name="btnAddTopic" type="button" id="btnAddTopic" value="Thêm đề tài" class="box" onClick="addTopic()"></td>
  </tr>
 </table>
 <p>&nbsp;</p>
</form>